<template>
  <div class="navigation-config">
    <div class="grid grid-cols-1 gap-4">
      <div>
        <label class="block text-sm font-medium text-gray-700 mb-1">目标URL</label>
        <el-input
          v-model="localStep.url"
          placeholder="https://example.com"
          size="small"
          @change="updateStep"
        >
          <template #prepend>
            <el-icon><i-ep-link /></el-icon>
          </template>
        </el-input>
      </div>
      
      <div class="grid grid-cols-2 gap-3">
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">等待加载完成</label>
          <el-select 
            v-model="localStep.waitUntil" 
            size="small"
            @change="updateStep"
          >
            <el-option label="DOM加载完成" value="domcontentloaded" />
            <el-option label="页面完全加载" value="load" />
            <el-option label="网络空闲" value="networkidle" />
          </el-select>
        </div>
        
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">超时时间 (ms)</label>
          <el-input-number
            v-model="localStep.timeout"
            :min="1000"
            :step="1000"
            size="small"
            class="w-full"
            @change="updateStep"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { Link as iEpLink } from '@element-plus/icons-vue'

const props = defineProps({
  step: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['update'])

const localStep = ref({
  url: '',
  waitUntil: 'domcontentloaded',
  timeout: 30000,
  ...props.step
})

watch(() => props.step, (newStep) => {
  localStep.value = {
    url: '',
    waitUntil: 'domcontentloaded',
    timeout: 30000,
    ...newStep
  }
}, { deep: true })

const updateStep = () => {
  emit('update', localStep.value)
}
</script>